<?php if(! defined('BASEPATH')) exit ('No direct script access allowed');
class laporan_keuangan extends CI_Controller{
	function __construct(){
		parent:: __construct();

		//$this->output->enable_profiler(true);
		$this->load->model('mdl_laporan_keuangan');
	}

	function index(){
		//$data['tgl_awal']='';
		//$data['tgl_akhir']='';

		$data['page_title']='Buat Laporan Keuangan';
		$data['page_icon']='icon-print';
		$data['page_content']='laporan_keuangan';

		$this->load->view('layout/master',$data);
	}

	function laporan(){
		//$data['tgl_awal']='';
		//$data['tgl_akhir']='';

		$data['page_title']='Buat Laporan Rekapitulasi Pemasukan Dan Pengeluaran';
		$data['page_icon']='icon-print';
		$data['page_content']='laporan_masuk_keluar';
		
		$this->load->view('layout/master',$data);
	}

	function print_data($tipe,$tgl_awal=null,$tgl_akhir=null){
		if ($tgl_awal == null || $tgl_akhir == null) {
			echo "Tanggal Awal Dan Tanggal Akhir Harus Di Isi";
			exit;
		}

		$this->load->library('HTML2PDF');
		$html2pdf = new HTML2PDF('L', 'A4', 'fr');
		$html2pdf->setDefaultFont('Arial');
		
		$data['alamat_des'] = 'Jl. Subang Raya No. 27';
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		//$data['tipe'] = $tipe;
		$tipe = $tipe;
		$tgl_awal = FormatDateToMysql(str_replace('-', '/', $tgl_awal));
		$tgl_akhir = FormatDateToMysql(str_replace('-', '/', $tgl_akhir));

		if ($tipe == 1) {
			# code...
			$data['tipe']  = 'Pemasukan';
			$data['total'] = $this->mdl_laporan_keuangan->sumdebit($tgl_awal,$tgl_akhir);
			$data['result'] = $this->mdl_laporan_keuangan->get_pdf($tgl_awal, $tgl_akhir,$tipe);

			$konten = $this->load->view('lap_keuangan', $data, true);
		}else if($tipe== 2){
			$data['tipe']  = 'Belanja';
			$data['total'] = $this->mdl_laporan_keuangan->sumkredit($tgl_awal,$tgl_akhir);
			$data['result'] = $this->mdl_laporan_keuangan->get_pdf($tgl_awal, $tgl_akhir,$tipe);

			$konten = $this->load->view('lap_keuangan', $data, true);
		}else{
			$data['tipe']  = 'Pemasukan & Belanja';
			$data['result2'] = $this->mdl_laporan_keuangan->getalltrans($tgl_awal, $tgl_akhir);
			//$data['result'] = $this->mdl_laporan_keuangan->get_pdf($tgl_awal, $tgl_akhir,$tipe);
			$konten = $this->load->view('lap_keuangan_all', $data, true);
		}
		

		$html2pdf->writeHTML($konten, false);
		
		$html2pdf->Output('lap_keuangan.pdf');
	}

	function print_data_lap($tgl_awal=null,$tgl_akhir=null){
		if ($tgl_awal == null || $tgl_akhir == null) {
			echo "Tanggal Awal Dan Tanggal Akhir Harus Di Isi";
			exit;
		}
		$this->load->library('HTML2PDF');
		$html2pdf = new HTML2PDF('P', 'A4', 'fr');
		$html2pdf->setDefaultFont('Arial');
		
		$data['alamat_des'] = 'Jl. Subang Raya No. 27';
		$data['tgl_awal'] = $tgl_awal;
		$data['tgl_akhir'] = $tgl_akhir;
		//$data['tipe'] = $tipe;
		//$tipe = $tipe;

		$tgl_awal = FormatDateToMysql(str_replace('-', '/', $tgl_awal));
		$tgl_akhir = FormatDateToMysql(str_replace('-', '/', $tgl_akhir));

		$data['debit'] = $this->mdl_laporan_keuangan->sumdebit($tgl_awal,$tgl_akhir);
		$data['kredit'] = $this->mdl_laporan_keuangan->sumkredit($tgl_awal,$tgl_akhir);

		
		$data['pemasukan'] = $this->mdl_laporan_keuangan->get_pendapatan($tgl_awal,$tgl_akhir);
		$data['pengeluaran'] = $this->mdl_laporan_keuangan->get_pengeluaran($tgl_awal,$tgl_akhir);
		// foreach ($parent->result() as $row) {
		// 	# code...
		// }
		$data['result'] = $this->mdl_laporan_keuangan->get_pdf_lap($tgl_awal, $tgl_akhir);

		$konten = $this->load->view('lap_masuk_keluar', $data, true);

		$html2pdf->writeHTML($konten, false);
		
		$html2pdf->Output('lap_keuangan.pdf');
	}
}
?>